import wx from "weixin-js-sdk";
import Axios from 'axios'
import {Toast} from 'vant';
import base from "../api/base";

function yyr(date) {
    let year = date.getFullYear();
    let month = date.getMonth() + 1;
    let day = date.getDate();
    return year + '-' + month + '-' + day
    // let date = new Date()
    // let year = date.getFullYear().toString()   //'2019'
    // let month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1).toString() : (date.getMonth() + 1).toString()  //'04'
    // let day = date.getDate() < 10 ? '0' + date.getDate().toString() : date.getDate().toString()  //'12'
    // let dateVals = year + '-' + month + '-' + day
    // return dateVals
}

function getNowTime() {
    var date = new Date()
    const year = date.getFullYear().toString() // '2019'
    // const month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1).toString() : (date.getMonth() + 1).toString() // '04'
    const month = date.getMonth() + 1 < 10 ? (date.getMonth() + 1).toString() : (date.getMonth() + 1).toString() // '04'
    const day = date.getDate() < 10 ? '0' + date.getDate().toString() : date.getDate().toString() // '12'

    // let newmonth = ''
    // if (da <= 10) {
    //     newmonth = '0'+(parseInt(month) - 1).toString()
    // } else {
    //     newmonth = month
    // }
    const datedc = year + '-' + month + '-' + day
    // console.log(datedc)
    return datedc
}

function years() {
    let date = new Date()
    let year = date.getFullYear().toString()
    let dateVals = year
    return dateVals
}

function Share() {
    Axios.post(base.baseUrl+'/weekly/index/wejssdk', {
    // Axios.post('/weekly/index/wejssdk', {
        url: window.location.href
    }).then(res => {
        console.log('打印出结果')
        console.log(res)
        if (res.data.code == 0) {
            wx.config({
                debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
                appId: res.data.data.appId, // 必填，公众号的唯一标识
                timestamp: res.data.data.timestamp, // 必填，生成签名的时间戳
                nonceStr: res.data.data.nonceStr, // 必填，生成签名的随机串
                signature: res.data.data.signature,// 必填，签名，见附录1
                jsApiList: res.data.data.jsApiList
                //showOptionMenu   开启
            })
            // 'menuItem:favorite',
            wx.ready(function () {
                // wx.hideOptionMenu()
                // wx.hideMenuItems({ // 要隐藏的菜单项，只能隐藏“传播类”和“保护类”按钮，所有menu项见附录3
                //     menuList: ['menuItem:share:appMessage', 'menuItem:share:timeline', "menuItem:share:weiboApp", 'menuItem:share:qq',  'menuItem:share:QZone', 'menuItem:openWithSafari', 'menuItem:copyUrl', 'menuItem:share:email',"menuItem:openWithQQBrowser"]
                // })
                // wx.showMenuItems({
                //     menuList:['menuItem:favorite']
                // });
            })
        } else {
            Toast.fail(res.msg)
        }
    }).catch(err => {
        console.log(err)
    })
}


function removexs(number) {
    return parseFloat(Number(number).toFixed(2))
}


export {
    yyr,
    getNowTime,
    Share,
    removexs
}
